package leetcode;

import java.util.HashSet;
import java.util.Set;

public class LC8 {
    public static void main(String[] args) {
        LC8 lc8 = new LC8();
        System.out.println(lc8.lengthOfLongestSubstring("abcabcbb"));
    }
    public int lengthOfLongestSubstring(String s) {
        if(s.length() == 0) return 0;
        Set<Character> ch = new HashSet<>();
        int max = 0;
        for(int i = 0,j = 0; i< s.length() && j < s.length();){
            if(ch.contains(s.charAt(j))){
                ch.remove(s.charAt(i++));
            }else{
                ch.add(s.charAt(j));
                j++;
            }
            max = Math.max(max, ch.size());
        }
        return max;
    }
}
